/**
 * 
 */
package trunk.frontend;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.File;
import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;

/**
 * @author Lawrence
 *
 */
public class ComponentLabelDialog extends JFrame implements WindowListener, ActionListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/* width and height*/
	private static final int WIDTH = 380, HEIGHT = 150;	
	
	JButton cancelButton;
	
	JButton submitButton;
	
	ButtonGroup group;
	
	JTextArea textField;
	
	private int cType = 0;
	
	int TYPE_TEXTBOX = 1;
	
	int TYPE_RADIOBUTTON = 2;
	
	int TYPE_LIKERT = 3;
	
	int TYPE_CHECKBOX = 4;
	
	String text;
	
	int number;
	
	JRadioButton checkBox;
	JRadioButton likert;
	JRadioButton radioButton;
	JRadioButton textbox;
	JRadioButton falseButton;
	
	
	public ComponentLabelDialog() {
			
		setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		initializeContentPane();
	
	}
	

	public void initializeContentPane() {
		
		setLocation(200, 200);
		
		//create label
		
		JLabel numOfComponent = new JLabel("Sublabel for component");
		
		
		//label Panel
	//	JPanel labelPanel = new JPanel(new GridLayout(0, 1));
		
	//	labelPanel.add(numOfComponent);
	//	labelPanel.add(Box.createVerticalStrut(50));
		
		
		
		//		create field
	    JPanel fieldPanel = new JPanel(new GridLayout(0, 1));
		
	    JLabel tempLabel = new JLabel("   ");
	    textField = new JTextArea(60,60);
	    fieldPanel.add(numOfComponent);
		fieldPanel.add(textField);
		//fieldPanel.add(Box.createVerticalStrut(10));
		
		//field Panel
		JPanel componentPanel = new JPanel(new GridLayout(0, 1));
				
		componentPanel.add(fieldPanel);
		
		componentPanel.add(Box.createVerticalStrut(50));
		
		//Button Panel
		submitButton = new JButton("Submit");		
		submitButton.addActionListener(this);		
		submitButton.setMnemonic(KeyEvent.VK_S);		
		JPanel submitPanel = new JPanel();
		submitPanel.add(submitButton);
		
		
		
		JPanel buttonPanel = new JPanel();
		buttonPanel.setLayout
		(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
		buttonPanel.add(Box.createRigidArea(new Dimension(0,3)));
		
		buttonPanel.add(submitPanel);
	
			
		
		//sub panel
			
		JPanel subPanel = new JPanel(new BorderLayout());
	//	subPanel.add(labelPanel, BorderLayout.NORTH);
		subPanel.add(componentPanel, BorderLayout.CENTER);		
		
		
		
		JPanel mainPanel = new JPanel(new BorderLayout());		
		mainPanel.setPreferredSize(new Dimension(WIDTH, HEIGHT));		
		mainPanel.add(subPanel, BorderLayout.CENTER);      
		mainPanel.add(buttonPanel, BorderLayout.SOUTH); 
		
		mainPanel.setBorder(
				new TitledBorder(new EtchedBorder(),
						"Enter SubLabel",
						TitledBorder.DEFAULT_JUSTIFICATION
						, TitledBorder.CENTER,
						new Font("Helvetica", Font.BOLD, 17)
						, new Color(0, 0, 250)));
		
		getContentPane().add(mainPanel);
		pack();
	}
	

	public void windowActivated(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}


	public void windowClosed(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}


	public void windowClosing(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}


	public void windowDeactivated(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}


	public void windowDeiconified(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}


	public void windowIconified(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}


	public void windowOpened(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}


	public void actionPerformed(ActionEvent e) {
		
	
		if (e.getSource() == submitButton) {
			//setVisible(false);		
			System.out.println(this.textField.getText());
			text = this.textField.getText();
			textField.setText("");
			
			int counter=0;
			
			for( counter=0; counter<number; counter++ ) {
				
				
				
			}
			
			//TODO
		}

	}
	
	public void setNumber(int number) {
		
		this.number = number;
		
	}

	public static void main(String[] args) {
		ComponentLabelDialog frame = new ComponentLabelDialog();
		
		frame.setVisible(true);
	}
	
	
}
